package com.example.sudoku;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class TecladoActivity extends Activity {
	
	Button[] teclado = new Button[9];
	Button btnApagar,btnCancelar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_teclado);
		
		teclado[0] = (Button) findViewById(R.id.t1);
		teclado[1] = (Button) findViewById(R.id.t2);
		teclado[2] = (Button) findViewById(R.id.t3);
		teclado[3] = (Button) findViewById(R.id.t4);
		teclado[4] = (Button) findViewById(R.id.t5);
		teclado[5] = (Button) findViewById(R.id.t6);
		teclado[6] = (Button) findViewById(R.id.t7);
		teclado[7] = (Button) findViewById(R.id.t8);
		teclado[8] = (Button) findViewById(R.id.t9);

		btnApagar = (Button) findViewById(R.id.btnApagar);
		btnCancelar = (Button) findViewById(R.id.btnCancelar);
		
		/*Intent returnIntent = new Intent();
		setResult(RESULT_CANCELED, returnIntent);        
		finish();*/
		//for (int j=0; j<9; j++){
		btnApagar.setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", "");
				setResult(RESULT_OK,i);     
				finish();
			}
		});
		btnCancelar.setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {  
				finish();
			}
		});

		teclado[0].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[0].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});
		//}
		teclado[1].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[1].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});

		teclado[2].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[2].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});

		teclado[3].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[3].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});

		teclado[4].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[4].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});

		teclado[5].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[5].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});

		teclado[6].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[6].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});

		teclado[7].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[7].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});

		teclado[8].setOnClickListener (new View.OnClickListener (){
			public void onClick (View view) {
				Intent i = new Intent();
				i.putExtra("result", teclado[8].getText());
				setResult(RESULT_OK,i);     
				finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.teclado, menu);
		return true;
	}

}
